import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;

public class demo {


    @Test
    public void demo() throws IOException {
        XSSFWorkbook sheets = new XSSFWorkbook("C:\\Users\\htc\\Desktop\\工作簿1.xlsx");

        XSSFSheet sheetAt = sheets.getSheetAt(0);

        for (Row rows : sheetAt) {

            for (Cell cell : rows) {

                String str = cell.getStringCellValue();
                System.out.println(str);
            }
        }

        sheets.close();
    }


    @Test
    public void demo2() throws IOException {

        String path = "C:\\Users\\htc\\Desktop\\工作簿2.xlsx";
        XSSFWorkbook sheets = new XSSFWorkbook();

        XSSFSheet sheet = sheets.createSheet("黑马程序员");
        XSSFRow row_0 = sheet.createRow(0);
        row_0.createCell(0).setCellValue("姓名");
        row_0.createCell(1).setCellValue("籍贯");

        XSSFRow row_1 = sheet.createRow(01);
        row_1.createCell(0).setCellValue("张三");
        row_1.createCell(1).setCellValue("湖北");

        FileOutputStream fos = new FileOutputStream(path);
        sheets.write(fos);
        fos.flush();

        sheets.close();
        fos.close();
    }
}
